﻿using DHISInteroperability;
using DHISInteroperability.Authentication;
using DHISInteroperability.Resources;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ReportingManagement.Components.DHIS
{
    public class DHISDataBridge
    {
        private static AuthorizationAgent defaultAuthorizationAgent;
        private static string defaultBaseUrl;

        private AuthorizationAgent authorizationAgent;
        private string baseUrl;

        public DHISDataBridge()
        {
            if (authorizationAgent == null) authorizationAgent = defaultAuthorizationAgent;
            if (baseUrl == null) baseUrl = defaultBaseUrl;
        }

        public DHISDataBridge(string baseUrl, AuthorizationAgent agent)
        {
            this.baseUrl = baseUrl;
            this.authorizationAgent = agent;
        }

        public static AuthorizationAgent DefaultAuthorizationAgent 
        {
            get { return defaultAuthorizationAgent; }
            set { defaultAuthorizationAgent = value; }
        }
        public static string DefaultBaseUrl 
        {
            get { return defaultBaseUrl; }
            set { defaultBaseUrl = value; }
        }

        public List<dataSet> GetAllDataSets()
        {
            var dataTransferManager = new DataTransferManager(baseUrl, authorizationAgent);
            return dataTransferManager.GetAllDataSets();
        }

        public dataSet GetDataSet(string datasetId, params string[] displayFields)
        {
            var dataTransferManager = new DataTransferManager(baseUrl, authorizationAgent);
            return dataTransferManager.GetDataSet(datasetId, displayFields);
        }

        public dataSet GetDataSet(string datasetId)
        {
            var output = GetDataSet(datasetId, null);
            return output;
        }
    }
}
